package com.smsc.headend.task.engine.service.task.impl;

import cn.hutool.core.date.SystemClock;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smsc.headend.module.report.entity.LogReportHis;
import com.smsc.headend.task.engine.mapper.LogReportHisMapper;
import com.smsc.headend.task.engine.service.task.LogReportHisService;
import org.springframework.stereotype.Service;

@Service
public class LogReportHisServiceImpl  extends ServiceImpl<LogReportHisMapper, LogReportHis> implements LogReportHisService {
    @Override
    public LogReportHis saveReportLog(Long seqId, Long userId, Integer reportType, Long tvStart, Integer status, Long tvEnd, String filePath, String fileName, String desc) {
        LogReportHis logReportHis;
        if (seqId != null) {
            logReportHis = this.getById(seqId);
            if (logReportHis == null) {
                logReportHis = new LogReportHis();
            }
        } else {
            logReportHis = new LogReportHis();
        }
        if (userId != null) {
            logReportHis.setUserId(userId);
        }
        if (reportType != null) {
            logReportHis.setReportType(reportType);
        }
        if (tvStart != null) {
            logReportHis.setTvStart(tvStart);
        }
        if (status != null) {
            logReportHis.setStatus(status);
        }
        if (tvEnd != null) {
            logReportHis.setTvEnd(tvEnd);
        }
        if (StrUtil.isNotEmpty(filePath)) {
            logReportHis.setFilePath(filePath);
        }
        if (StrUtil.isNotEmpty(fileName)) {
            logReportHis.setFileName(fileName);
        }
        if (StrUtil.isNotEmpty(desc)) {
            logReportHis.setDescrb(desc);
        }
        this.saveOrUpdate(logReportHis);
        return logReportHis;
    }

    @Override
    public LogReportHis saveReportLog(LogReportHis logReportHis) {
        this.saveOrUpdate(logReportHis);
        return logReportHis;
    }
}
